#version 330 core

/*
//如果要将颜色输出到多个缓冲区，着色器必须配置为写入多重颜色输出：
layout(location = 0) out vec4 fragData0;
layout(location = 1) out vec4 fragData1;
layout(location = 2) out vec4 fragData2;
layout(location = 3) out vec4 fragData3;
//还要使用 glDrawBuffers设置写入路由 glReadBuffer设置读取的缓冲
*/

layout(location = 0) out vec4 FragColor;
layout(location = 1) out vec4 FragColor1;

in vec2 TexCoord;
in float zvalue; //  顶点的z值 -1~1 gl_FragCoord.z是这个值变换为0~1
uniform vec3 inputcolor;
//in vec4 refcolor;

uniform sampler2D texHandle1;         //默认对应对应GL_TEXTURE0 而且GL_TEXTURE0默认是激活了的
//uniform sampler2D texHandle2;       //多个2d 纹理采样器 通过glUniform1i设置索引号 对应glActiveTexture(GL_TEXTUREi)

void main(){
    float r = 0.0f;
    float c = zvalue + 1; // zvalue  减去负1
    c = c/2.0f;
    r = abs(gl_FragCoord.z - c) * 100000.0f;  //  乘以了很多倍，说明很接近0

    vec4 texcolor = texture(texHandle1,TexCoord);  //texture2D()函数好像不能用
    FragColor =  texcolor ; //* vec4(r, inputcolor.g, inputcolor.b, 0.2f)
//    FragColor =  vec4(gl_FragCoord.z);
    FragColor1 = vec4(inputcolor.g, inputcolor.b, r, 1000.2f) * texcolor;
//    gl_FragDepth = c;  //  输出计算的深度与自动生成的基本一至
}
